package com.zyg.apart.controller;

import com.github.pagehelper.PageInfo;
import com.zyg.apart.model.Flatplay;
import com.zyg.apart.service.FlatplayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

/**
 * 活动控制层
 */
@Controller
@RequestMapping("/play")
public class FlatplayController {
	@Autowired
	private FlatplayService flatplayService;

	@RequestMapping("/list")
	public String list(Integer currentPage, Model model){
		if (currentPage == null){
			currentPage = 1;
		}
		PageInfo<Map<String,Object>> plays = flatplayService.getAllPlay(currentPage);
		model.addAttribute("plays",plays);
		return "play/list";
	}

	@RequestMapping("/detail")
	public String detail(Model model,Integer id){
		Flatplay flatplay = flatplayService.getPlayById(id);
		model.addAttribute("flatplay",flatplay);
		return "play/detail";
	}

	@RequestMapping("/toEdit")
	public String toEdit(Model model, Integer id){
		Flatplay flatplay = flatplayService.getPlayById(id);
		model.addAttribute("flatplay",flatplay);
		return "play/edit";
	}

	@RequestMapping("/edit")
	public String edit(Flatplay flatplay){
		System.out.println(flatplay);
		int i = flatplayService.editPlay(flatplay);
		return "forward:list";
	}

	@RequestMapping("/del")
	public String del(Integer id){
		int i = flatplayService.delPlayById(id);
		return "forward:list";
	}

	@RequestMapping("/toAdd")
	public String toAdd(){
		return "play/add";
	}

	@RequestMapping("/add")
	public String add(Flatplay flatplay){
		System.out.println(flatplay);
		int i = flatplayService.addPlay(flatplay);
		return "forward:list";
	}

}
